package com.corpcredit.webapp.action;

import java.io.Serializable;

import com.corpcredit.model.Gjfxx;
import com.corpcredit.model.Jbqk;
import com.corpcredit.service.GenericManager;
import com.corpcredit.service.LookupManager;

public class GjfxxForm extends BasePage implements Serializable {
	private GenericManager<Gjfxx, Long> gjfxxManager;

	private Gjfxx gjfxx = new Gjfxx();
	private Long id;

	private LookupManager lookupManager;
	
	public void setLookupManager(LookupManager lookupManager) {
		this.lookupManager = lookupManager;
	}

	public void setGjfxxManager(GenericManager<Gjfxx, Long> gjfxxManager) {
		this.gjfxxManager = gjfxxManager;
	}

	public Gjfxx getGjfxx() {
		Jbqk jbqk = getJbqk();
		if (jbqk != null && jbqk.getId() != null) {
			gjfxx = (Gjfxx) lookupManager.findByJbqkID(Gjfxx.class, jbqk.getId());
		}
		if(gjfxx == null)
		{
			gjfxx = new Gjfxx();
		}
		return gjfxx;
	}

	public void setGjfxx(Gjfxx gjfxx) {
		this.gjfxx = gjfxx;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String delete() {
		gjfxxManager.remove(gjfxx.getId());
		addMessage("gjfxx.deleted");

		return "edit";
	}

	public String save() {
		boolean isNew = (gjfxx.getId() == null || gjfxx.getId() == 0);
		gjfxxManager.save(gjfxx);

		String key = (isNew) ? "gjfxx.added" : "gjfxx.updated";
		addMessage(key);

		return "edit";
	}
}